<template>
    <div class="my">
      <div class="top">
        <div class="top1">
          <div class="left">
            <p class="name">{{userInfo.nickname}}</p>
            <p class="text">{{userInfo.intro}}</p>
          </div>
          <img class="right" v-if="userInfo.avatar" :src="baseUrl+userInfo.avatar" alt="" @click="goMyInfo">
          <img src="@/assets/logo.png" v-else alt="" class="right" @click="goMyInfo">
        </div>
        <div class="top2">
          <div class="item">
            <p class="num">{{userInfo.submitNum}}</p>
            <p class="txt">累计答题</p>
          </div>
          <div class="item">
            <p class="num" v-text="userInfo.collectQuestions.length"><!--{{userInfo.collectQuestions.length}}--></p>
            <p class="txt">收藏题目</p>
          </div>
          <div class="item">
            <p class="num">{{userInfo.errorNum}}</p>
            <p class="txt">我的错题</p>
          </div>
          <div class="item">
            <p class="num" v-if="userInfo.submitNum === 0">0%</p>
            <p class="num" v-else>{{Math.floor((userInfo.submitNum - userInfo.errorNum) / userInfo.submitNum * 100)}}%</p>
            <p class="txt">正确率</p>
          </div>
        </div>
        <div class="top3">
          <myCell
            class="cell"
            title="我的岗位"
            :value="userInfo.position"
            icon='&#xe64d;'
            @click.native="$router.push('/home/editInfo?type=position')"></myCell>
        </div>
      </div>
      <div class="content">
        <div class="middle">
          <p class="middle-title">面经数据</p>
          <ul class="middle-content">
            <li class="item">
              <p class="item-top">
                昨日阅读
                <span>+{{userInfo.shareData.read.yesterday}}</span>
              </p>
              <p class="item-middle">
                {{userInfo.shareData.read.total}}
              </p>
              <p class="item-bottom">
                阅读总数
              </p>
            </li>
            <li class="item">
              <p class="item-top">
                昨日获赞
                <span>+{{userInfo.shareData.star.yesterday}}</span>
              </p>
              <p class="item-middle">
                {{userInfo.shareData.star.total}}
              </p>
              <p class="item-bottom">
                阅读获赞
              </p>
            </li>
            <li class="item">
              <p class="item-top">
                昨日新增
                <span>+{{userInfo.shareData.comment.yesterday}}</span>
              </p>
              <p class="item-middle">
                {{userInfo.shareData.comment.total}}
              </p>
              <p class="item-bottom">
                评论总数
              </p>
            </li>
          </ul>
        </div>
        <div class="bottom">
          <my-cell title="我的面经分享" value="21" icon='&#xe655;'></my-cell>
          <my-cell title="我的消息" :value="userInfo.systemMessages.toString()" icon="&#xe656;"></my-cell>
          <my-cell title="收藏的题库" :value="userInfo.collectQuestions.length.toString()" icon="&#xe654;"></my-cell>
          <my-cell title="收藏的企业" value="32" icon="&#xe648;"></my-cell>
          <my-cell title="我的错题" :value="userInfo.errorNum.toString()" icon="&#xe64f;"></my-cell>
          <my-cell title="收藏的面试经验" value="42" icon="&#xe649;"></my-cell>
        </div>
      </div>
    </div>
</template>

<script>
import myCell from './myCell'
import { mapState } from 'vuex'
export default {
  name: 'my',
  components: {
    myCell
  },
  data () {
    return {
      baseUrl: process.env.VUE_APP_URL
    }
  },
  computed: {
    ...mapState(['userInfo'])
  },
  methods: {
    goMyInfo () {
      this.$router.push('/home/myInfo')
    }
  }
}
</script>

<style lang="less" scoped>
  .my{
    .top{
      position: relative;
      background-color: #c1002e;
      padding: 31px @p15 0;
      .top1 {
        display: flex;
        justify-content: space-between;
        .left{
          .name{
            margin-bottom: 6px;
            font-size: 21px;
            font-family: PingFangSC, PingFangSC-Semibold;
            font-weight: 600;
            text-align: left;
            color: #ffffff;
            line-height: 30px;
            letter-spacing: 0px;
          }
          .text {
            opacity: 0.7;
            font-size: 12px;
            font-family: PingFangSC, PingFangSC-Regular;
            font-weight: 400;
            text-align: left;
            color: #ffffff;
            line-height: 16px;
            letter-spacing: 0px;
          }
        }
        .right {
          width: 50px;
          height: 50px;
          border: 3px solid rgba(255,255,255,0.38);
          border-radius: 50%;
        }
      }
      .top2 {
        margin-top: 31px;
        padding-bottom: 55px;
        display: flex;
        justify-content: space-between;
        .item {
          .num {
            margin-bottom: 6px;
            font-size: 21px;
            font-family: DINAlternate, DINAlternate-Bold;
            font-weight: 700;
            text-align: center;
            color: #ffffff;
            line-height: 24px;
            letter-spacing: 0px;
          }
          .txt {
            opacity: 0.7;
            font-size: 12px;
            font-family: PingFangSC, PingFangSC-Regular;
            font-weight: 400;
            text-align: center;
            color: #ffffff;
            line-height: 16px;
            letter-spacing: 0px;
          }
        }
      }
      .top3 {
        position: absolute;
        left: 0;
        bottom: -16px;
        width: 100%;
        padding: 0 @p15;
        .cell {
          border-radius: 8px;
        }
      }
    }
    .content {
      padding: 26px @p15 20px;
      background-color: #f7f4f5;
      .middle {
        background-color: #ffffff;
        border-radius: 8px;
        padding: 19px 15px;
        margin-bottom: 10px;
        .middle-title {
          font-size: 14px;
          font-family: PingFangSC, PingFangSC-Semibold;
          font-weight: 600;
          text-align: left;
          color: #181a39;
          line-height: 20px;
          letter-spacing: 0px;
          margin-bottom: 17px;
        }
        .middle-content {
          display: flex;
          justify-content: space-between;
          .item {
            .item-top {
              font-size: 12px;
              font-family: PingFangSC, PingFangSC-Regular;
              font-weight: 400;
              text-align: center;
              color: #b4b4bd;
              line-height: 14px;
              letter-spacing: 0px;
              span {
                color: #00B8D4;
              }
            }
            .item-middle {
              font-size: 21px;
              font-family: DINAlternate, DINAlternate-Bold;
              font-weight: 700;
              text-align: center;
              color: #181a39;
              line-height: 24px;
              letter-spacing: 0px;
              margin: 10px 0 6px;
            }
            .item-bottom {
              font-size: 12px;
              font-family: PingFangSC, PingFangSC-Regular;
              font-weight: 400;
              text-align: center;
              color: #545671;
              line-height: 16px;
              letter-spacing: 0px;
            }
          }
        }
      }
      .bottom {
        background: #ffffff;
        border-radius: 8px;
        overflow: hidden;
      }
    }
  }
</style>
